//
//  SinaBaseTableViewController.m
//  oc微博
//
//  Created by 安陆与 on 16/1/14.
//  Copyright © 2016年 安陆与. All rights reserved.
//

#import "SinaBaseTableViewController.h"
#import "SinaVisitorVIew.h"
#import "SinaOauthViewController.h"
#import "SinaAccountViewModel.h"

@interface SinaBaseTableViewController ()<SinaVisitorVIewDelegate>

@property (nonatomic,assign)BOOL isLogin;


@property (nonatomic, strong)SinaVisitorVIew *visitor;

//@property (nonatomic,weak)UIView *view;


@end

@implementation SinaBaseTableViewController


-(void)loadView{

    
//    [super loadView];
    
//    _isLogin = ([[[SinaAccountViewModel alloc]init].access_token  isEqual: nil])?NO:YES;
    _isLogin = [[SinaAccountViewModel alloc]init].access_token;
    
//    _isLogin = ([[SinaAccountViewModel shareAccount].access_token isEqual:nil])?NO:YES;
    
//    if (![SinaAccountViewModel shareAccount].access_token) {
//        _isLogin = NO;
//        NSLog(@"这里是空的");
//    }else{
//    
//        _isLogin = YES;
//    }
    
//    NSLog(@"%@",[SinaAccountViewModel shareAccount].access_token);
//    if (_isLogin) {
//        
//        [super loadView];
//
//    }else{
    
//        NSLog(@"是空的走这里");
//        _visitor = [[SinaVisitorVIew alloc]init];
//        
//        [self.view addSubview:_visitor];
//    
//        _visitor.delegate = self;
//        
//        _visitor.frame = self.view.bounds;
    
//        }
    
    if (_isLogin) {
        
        [super loadView];
        
    }else{
        
        [super loadView];
        
        [self setupNav];

//        SinaVisitorVIew *visitor = [[SinaVisitorVIew alloc]init];
        
        _visitor = [[SinaVisitorVIew alloc]init];
//        self.visitor = visitor;
        
        [self.view addSubview:_visitor];
        
//        self.view = _visitor;
        
        _visitor.delegate = self;
        
        _visitor.frame = self.view.bounds;
        
//        NSLog(@"sdsdasdasda");
    
    }
    
    


}

//- (void)viewDidLoad {
//    [super viewDidLoad];
//    
//    
////    [view startAnimation];
//
//}

//设置nav
-(void)setupNav{

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(didRegisterMethod)];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(didLoginMethod)];


}

-(void)didClickLogin{

    [self didLoginMethod];
}

-(void)didClickRegister{

    [self didRegisterMethod];
}

//注册
-(void)didRegisterMethod{

    NSLog(@"注册点击了");
}

//登录didLoginMethod
-(void)didLoginMethod{

    NSLog(@"登录点击了");
    
    SinaOauthViewController *oauth = [[SinaOauthViewController alloc]init];
    
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:oauth];
    
    [self presentViewController:nav animated:YES completion:^{
        
    }];
}




@end
